package com.itheima.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.itheima.constant.MessageConst;
import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.pojo.CheckGroup;
import com.itheima.service.CheckGroupService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;

@RestController
@Slf4j
@RequestMapping("/checkgroup")
public class CheckGroupController {
    @Reference
    private CheckGroupService checkGroupService;

    @RequestMapping("/findByPage")
    public Result findByPage(@RequestBody QueryPageBean queryPageBean) {
        log.debug("CheckGroupController__findByPage:{" + queryPageBean + "}");
        PageResult pageResult = checkGroupService.findByPage(queryPageBean);
        log.debug(MessageConst.QUERY_CHECKGROUP_SUCCESS);
        return new Result(true, MessageConst.QUERY_CHECKGROUP_SUCCESS, pageResult);
    }

    @RequestMapping("/add")
    public Result add(Integer[] checkitemIds, @RequestBody CheckGroup checkGroup) {
        log.debug("CheckGroupController__add:{" + Arrays.toString(checkitemIds) + "}");
        log.debug("CheckGroupController__add:{" + checkGroup + "}");
        checkGroupService.add(checkitemIds, checkGroup);
        log.debug(MessageConst.ADD_CHECKGROUP_SUCCESS);
        return new Result(true, MessageConst.ADD_CHECKGROUP_SUCCESS);
    }

    @RequestMapping("/deleteById")
    public Result findById(Integer id) {
        log.debug("CheckGroupController__deleteById:{" + id + "}");
        checkGroupService.deleteById(id);
        log.debug(MessageConst.DELETE_CHECKGROUP_SUCCESS);
        return new Result(true, MessageConst.DELETE_CHECKGROUP_SUCCESS);
    }
}
